package com.sinoglobal.ningxia.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.sinoglobal.ningxia.beans.NewsSectionListVo;
import com.sinoglobal.ningxia.fragment.NewsFragment;
import com.sinoglobal.ningxia.utils.ItktLog;

public class NewsFragmentStatePagerAdapter extends FragmentStatePagerAdapter {

    NewsSectionListVo newsSectionListVo;

    public NewsFragmentStatePagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void setData(NewsSectionListVo newsSectionListVo) {
        this.newsSectionListVo = newsSectionListVo;
        notifyDataSetChanged();
    }


    @Override
    public Fragment getItem(int position) {
        NewsFragment fragment = NewsFragment.newInstance(newsSectionListVo.getNews_cate().get(position));
        ItktLog.i("NewsFragmentStatePagerAdapter.getItem==" + fragment);
        return fragment;
    }

    @Override
    public int getCount() {
        if (newsSectionListVo == null || newsSectionListVo.getNews_cate() == null) {
            return 0;
        }
        return newsSectionListVo.getNews_cate().size();

    }

    public CharSequence getPageTitle(int position) {
        String pageTitle = newsSectionListVo.getNews_cate().get(position).getClass_name();
        return pageTitle;
    }


}